﻿using System;
using System.Web;
using System.Xml.Serialization;
using System.IO;

public class XMLSerialization
{
    public static object Deserialize(Type _objectType, string _filePath)
    {
        XmlSerializer serializer;
        TextReader textReader = null;
        object obj2 = null;
        try
        {
            serializer = new XmlSerializer(_objectType);
            textReader = new StreamReader(HttpContext.Current.Server.MapPath(_filePath));
            obj2 = serializer.Deserialize(textReader);
        }
        catch { }
        finally
        {
            textReader.Close();
        }
        return obj2;

    }

    public static void Serialize(Type _objectType, object _objectToSerialize, string _filePath)
    {
        XmlSerializer serializer;
        TextWriter textWriter = null;
        try
        {
            serializer = new XmlSerializer(_objectType);
            textWriter = new StreamWriter(HttpContext.Current.Server.MapPath(_filePath));
            serializer.Serialize(textWriter, _objectToSerialize);
        }
        catch { }
        finally
        {
            textWriter.Flush();
            textWriter.Close();
            textWriter.Dispose();
        }
    }
}

